"use strict";

module.exports = {
    BasicTools: {
        PortRangeDetect(PortNumber) {
            let FinalDetectValue = false;
            if (Object.prototype.toString.call(PortNumber) === "[object Number]") {
                if (PortNumber > 1 && PortNumber < 65535) {
                    FinalDetectValue = true;
                }
            }
            return FinalDetectValue;
        },
        Light_Copy(DataSource) {
            return DataSource;
        },
        emptyArrDetect(Arr) {
            if (Object.prototype.toString.call(Arr) === "[object Array]") {
                if (Arr.length > 0) {
                    return false;
                } else {
                    return true;
                }
            } else {
                return undefined
            }
        },
        emptyObjDetect(Obj) {
            if (Object.prototype.toString.call(Obj) === "[object Object]") {
                let num = 0;
                for (let count in Obj) {
                    num++;
                    if (num > 3) {
                        break;
                    }
                }
                if (num > 0) {
                    return false;
                } else {
                    return true;
                }
            } else {
                return undefined;
            }
        },
        FileStream: require('fs'),
        PathStream: require('path')
    },
    ModeLauncherSelect(InstanceHandle) {
        let finalMode;
        if (InstanceHandle.EnableHttpMode && InstanceHandle.EnableHttpsMode) {
            finalMode = "both";
        } else if (InstanceHandle.EnableHttpMode && !InstanceHandle.EnableHttpsMode) {
            finalMode = "http";
        } else if (!InstanceHandle.EnableHttpMode && InstanceHandle.EnableHttpsMode) {
            finalMode = "https";
        } else {
            finalMode = undefined;
        }
        return finalMode;
    },
    InstanceIntegrityVerify(InstanceHandle) {
        let FinalIntegrityVerifyValue;
        try {
            let AttrCount = 0;
            switch (Object.prototype.toString.call(InstanceHandle)) {
                case "[object Object]":
                    if (InstanceHandle.__MeTools.BasicTools.emptyObjDetect(InstanceHandle) === false) {
                        for (let checkAttr in InstanceHandle) {
                            switch (checkAttr) {
                                case "__InstanceCollect_Root":
                                    AttrCount++;
                                    break;
                                case "__MeTools":
                                    AttrCount++;
                                    break;
                                case "__Core":
                                    AttrCount++;
                                    break;
                                case "__ToolKit":
                                    AttrCount++;
                                    break;
                                case "__GenTools":
                                    AttrCount++;
                                    break;
                                case "__Global_Event":
                                    AttrCount++;
                                    break;
                                case "SpecialSupport":
                                    AttrCount++;
                                    break;
                                case "SSLPrivateKey":
                                    AttrCount++;
                                    break;
                                case "SSLCertificate":
                                    AttrCount++;
                                    break;
                                case "ServicePort":
                                    AttrCount++;
                                    break;
                                case "ServiceHost":
                                    AttrCount++;
                                    break
                                case "ExternalImportRouter":
                                    AttrCount++;
                                    break;
                                case "EnableHistoryRouter":
                                    AttrCount++;
                                    break;
                                case "EnableHttpsMode":
                                    AttrCount++;
                                    break;
                                case "EnableHttpMode":
                                    AttrCount++;
                                    break;
                                case "DefaultPage":
                                    AttrCount++;
                                    break;
                                case "DefaultRootPath":
                                    AttrCount++;
                                    break;
                                case "GlobalEventProcess":
                                    AttrCount++;
                                    break;
                                case "GlobalEventJoinPoint":
                                    AttrCount++;
                                    break;
                                case "NoRequiredStaticResources":
                                    AttrCount++;
                                    break;
                                case "log_clean":
                                    AttrCount++;
                                    break;
                                case "log_export":
                                    AttrCount++;
                                    break;
                                default:
                                    throw new Error("检测出貌似不是本模块的实例对象的属性！");
                            }
                        }
                    } else {
                        throw new Error("传递过来的是一个空的实例对象！");
                    }
                    if (AttrCount !== 22) {
                        throw new Error("貌似不是本模块的实例对象！");
                    }
                    break;
                default:
                    throw new Error("形参必须是实例对象！");
            }
            FinalIntegrityVerifyValue = true;
        } catch (e) {
            InstanceHandle.__InstanceCollect_Root.consoleLogStream.addonLog(InstanceHandle, `${e.message}\r\n${e.stack}`, 'Fail');
            FinalIntegrityVerifyValue = false;
        }
        return FinalIntegrityVerifyValue;
    },
    RouterMiddlewareCheck(Instance, RouterSource) {
        let FinalCheckValue;
        try {
            switch (Object.prototype.toString.call(RouterSource)) {
                case "[object Object]":
                    if (Instance.__MeTools.BasicTools.emptyObjDetect(RouterSource)) {
                        throw new Error("传递过来的路由数据源是空对象！");
                    } else {
                        for (let RouterNameCheck in RouterSource) {
                            if (RouterNameCheck.charAt(0) === '/' && RouterNameCheck.indexOf('/') >= 0) {
                                if (typeof RouterSource[RouterNameCheck] !== "function") {
                                    throw new Error("路由对应的是非函数、非异步函数！");
                                }
                            } else {
                                throw new Error("路由路径名称不规范！");
                            }
                        }
                    }
                    break;
                case "[object Array]":
                    if (Instance.__MeTools.BasicTools.emptyArrDetect(RouterSource)) {
                        throw new Error("传递过来的路由数据源是空数组！");
                    } else {
                        for (let arrNum = 0; arrNum < RouterSource.length; arrNum++) {
                            switch (Object.prototype.toString.call(RouterSource[arrNum])) {
                                case "[object Object]":
                                    if (Instance.__MeTools.BasicTools.emptyObjDetect(RouterSource[arrNum]) === false) {
                                        let ValidAttrCount = 0;
                                        for (let ArrRouteAttr in RouterSource[arrNum]) {
                                            switch (ArrRouteAttr.toLowerCase()) {
                                                case "routername":
                                                    if (typeof RouterSource[arrNum][ArrRouteAttr] !== "string" || RouterSource[arrNum][ArrRouteAttr].charAt(0) !== '/') {
                                                        throw new Error("RouterName属性仅能为字符串，且必须符合路由名称规范！");
                                                    }
                                                    ValidAttrCount++;
                                                    break;
                                                case "middleware":
                                                    if (typeof RouterSource[arrNum][ArrRouteAttr] !== "function") {
                                                        throw new Error("MiddleWare属性仅能对应的是函数或异步函数！");
                                                    }
                                                    ValidAttrCount++;
                                                    break;
                                                case "servertype":
                                                    if (typeof RouterSource[arrNum][ArrRouteAttr] !== "string") {
                                                        throw new Error("ServerType属性的值仅能为字符串，仅能为“http”，“https”，“global”，默认值为“global”。");
                                                    }
                                                    break;
                                                default:
                                                    throw new Error("ExternalImportRouter属性包含的数组内的对象出现异常！");
                                            }
                                        }
                                        if (ValidAttrCount !== 2) {
                                            throw new Error("有效属性不足！");
                                        }
                                    } else {
                                        throw new Error("数组中出现无效对象！");
                                    }
                                    break;
                                default:
                                    throw new Error("数组中包含了非对象类的数据！");
                            }
                        }
                    }
                    break;
                default:
                    throw new Error("传递过来的路由数据源不是对象或数组！");
            }
            FinalCheckValue = true;
        } catch (e) {
            Instance.__InstanceCollect_Root.consoleLogStream.addonLog(Instance, `${e.message}\r\n${e.stack}`, 'Fail');
            FinalCheckValue = false;
        }
        return FinalCheckValue;
    },
    IPAddressComps(Instance, NeedCompData) {
        let ServerHostBaseInfo = {
            HostName: require('os').hostname(),
            InternetProtocol_v4: Instance.__ToolKit.getCurrentHostIPAddress("ipv4"),
            InternetProtocol_v6: Instance.__ToolKit.getCurrentHostIPAddress("ipv6")
        }
        let detectPass = false;
        let CompSource = [ServerHostBaseInfo.HostName, "localhost", "127.0.0.1", "::1", "0.0.0.0"];
        if (typeof ServerHostBaseInfo.InternetProtocol_v4 === "object" && ServerHostBaseInfo.InternetProtocol_v4.length > 0) {
            CompSource.push(...ServerHostBaseInfo.InternetProtocol_v4);
        }
        if (typeof ServerHostBaseInfo.InternetProtocol_v6 === "object" && ServerHostBaseInfo.InternetProtocol_v6.length > 0) {
            CompSource.push(...ServerHostBaseInfo.InternetProtocol_v6);
        }
        try {
            for (let num in CompSource) {
                switch (String().toLowerCase()) {
                    case "localhost":
                        detectPass = true;
                        throw new Error("");
                    case "127.0.0.1":
                        detectPass = true;
                        throw new Error("");
                    case "::1":
                        detectPass = true;
                        throw new Error("");
                    default:
                        if (String(NeedCompData).toString() === String(CompSource[num]).toString()) {
                            detectPass = true;
                            throw new Error("");
                        }
                        break;
                }
            }
        } catch (e) {

        }
        if (detectPass) {
            return true;
        } else {
            return false;
        }
    },
    ConfigureDataVerify(Instance, NeedVerifyDataObject) {
        let tempTestObject = {
            EnableHttpMode: false,
            EnableHttpsMode: false,
            ExternalImportRouter: undefined,
            EnableHistoryRouter: false,
            DefaultRootPath: undefined,
            DefaultPage: undefined,
            SSLPrivateKey: undefined,
            SSLCertificate: undefined,
            ServiceHost: {http: undefined, https: undefined},
            ServicePort: {http: 80, https: 443},
            SpecialSupport: undefined,
            NoRequiredStaticResources: false,
            GlobalEventJoinPoint: undefined
        }
        let VerifyBooleanValue;
        try {
            if (Instance.__MeTools.BasicTools.emptyObjDetect(NeedVerifyDataObject)) {
                throw new Error("需要校验的数据是空对象！");
            } else {
                function arrRouterDetect(routerData) {
                    let ddr = 0;
                    let FinalVal = [];
                    for (let nums in routerData) {
                        switch (nums.toLowerCase()) {
                            case "routername":
                                FinalVal[0] = routerData[nums];
                                ddr++;
                                break;
                            case "middleware":
                                FinalVal[1] = routerData[nums];
                                ddr++;
                                break;
                            case "servertype":
                                FinalVal[2] = routerData[nums];
                                ddr++;
                                break;
                        }
                    }
                    if (ddr >= 2) {
                        FinalVal.push(true);
                    } else {
                        FinalVal.push(false);
                    }
                    return FinalVal;
                }

                for (let initCheckItem in NeedVerifyDataObject) {
                    switch (String(initCheckItem).toLowerCase()) {
                        case "enablehttpmode":
                            if (Object.prototype.toString.call(NeedVerifyDataObject[initCheckItem]) !== "[object Boolean]") {
                                throw new Error("EnableHttpMode属性必须为布尔值！");
                            } else {
                                tempTestObject.EnableHttpMode = Instance.__MeTools.BasicTools.Light_Copy(NeedVerifyDataObject[initCheckItem]);
                            }
                            break;
                        case "enablehttpsmode":
                            if (Object.prototype.toString.call(NeedVerifyDataObject[initCheckItem]) !== "[object Boolean]") {
                                throw new Error("EnableHttpsMode属性必须为布尔值！");
                            } else {
                                tempTestObject.EnableHttpsMode = Instance.__MeTools.BasicTools.Light_Copy(NeedVerifyDataObject[initCheckItem]);
                            }
                            break;
                        case "externalimportrouter":
                            tempTestObject.ExternalImportRouter = {};
                            switch (Object.prototype.toString.call(NeedVerifyDataObject[initCheckItem])) {
                                case "[object Object]":
                                    for (let detectRouterImport in NeedVerifyDataObject[initCheckItem]) {
                                        switch (detectRouterImport.toLowerCase()) {
                                            case "http":
                                                if (Object.prototype.toString.call(NeedVerifyDataObject[initCheckItem][detectRouterImport]) === "[object Object]") {
                                                    if (Instance.__MeTools.BasicTools.emptyObjDetect(NeedVerifyDataObject[initCheckItem][detectRouterImport])) {
                                                        throw new Error("ExternalImportRouter属性包含的Http属性是空对象！");
                                                    } else if (!Instance.__MeTools.RouterMiddlewareCheck(Instance, NeedVerifyDataObject[initCheckItem][detectRouterImport])) {
                                                        throw new Error("需要导入的http路由存在异常！请通知开发人员。");
                                                    }
                                                    if (typeof tempTestObject.ExternalImportRouter.http !== "object") {
                                                        tempTestObject.ExternalImportRouter.http = {};
                                                    }
                                                    for (let imp1 in NeedVerifyDataObject[initCheckItem][detectRouterImport]) {
                                                        tempTestObject.ExternalImportRouter.http[imp1] = NeedVerifyDataObject[initCheckItem][detectRouterImport][imp1];
                                                    }
                                                } else {
                                                    throw new Error("ExternalImportRouter属性包含的Http属性不是对象！");
                                                }
                                                break;
                                            case "https":
                                                if (Object.prototype.toString.call(NeedVerifyDataObject[initCheckItem][detectRouterImport]) === "[object Object]") {
                                                    if (Instance.__MeTools.BasicTools.emptyObjDetect(NeedVerifyDataObject[initCheckItem][detectRouterImport])) {
                                                        throw new Error("ExternalImportRouter属性包含的Https属性是空对象！");
                                                    } else if (!Instance.__MeTools.RouterMiddlewareCheck(Instance, NeedVerifyDataObject[initCheckItem][detectRouterImport])) {
                                                        throw new Error("需要导入的https路由存在异常！请通知开发人员。");
                                                    }
                                                    if (typeof tempTestObject.ExternalImportRouter.https !== "object") {
                                                        tempTestObject.ExternalImportRouter.https = {};
                                                    }
                                                    for (let imp2 in NeedVerifyDataObject[initCheckItem][detectRouterImport]) {
                                                        tempTestObject.ExternalImportRouter.https[imp2] = NeedVerifyDataObject[initCheckItem][detectRouterImport][imp2];
                                                    }
                                                } else {
                                                    throw new Error("ExternalImportRouter属性包含的Https属性不是对象！");
                                                }
                                                break;
                                            case "global":
                                                if (Object.prototype.toString.call(NeedVerifyDataObject[initCheckItem][detectRouterImport]) === "[object Object]") {
                                                    if (Instance.__MeTools.BasicTools.emptyObjDetect(NeedVerifyDataObject[initCheckItem][detectRouterImport])) {
                                                        throw new Error("ExternalImportRouter属性包含的Global属性是空对象！");
                                                    } else if (!Instance.__MeTools.RouterMiddlewareCheck(Instance, NeedVerifyDataObject[initCheckItem][detectRouterImport])) {
                                                        throw new Error("需要导入的global路由存在异常！请通知开发人员。");
                                                    }
                                                    if (typeof tempTestObject.ExternalImportRouter.global !== "object") {
                                                        tempTestObject.ExternalImportRouter.global = {};
                                                    }
                                                    for (let imp3 in NeedVerifyDataObject[initCheckItem][detectRouterImport]) {
                                                        tempTestObject.ExternalImportRouter.global[imp3] = NeedVerifyDataObject[initCheckItem][detectRouterImport][imp3];
                                                    }
                                                } else {
                                                    throw new Error("ExternalImportRouter属性包含的Global属性不是对象！");
                                                }
                                                break;
                                            default:
                                                if (!Instance.__MeTools.RouterMiddlewareCheck(Instance, NeedVerifyDataObject[initCheckItem])) {
                                                    throw new Error("需要导入的路由存在异常！请通知开发人员。");
                                                } else {
                                                    if (typeof tempTestObject.ExternalImportRouter.global !== "object") {
                                                        tempTestObject.ExternalImportRouter.global = {};
                                                    }
                                                    for (let impsRouter in NeedVerifyDataObject[initCheckItem]) {
                                                        tempTestObject.ExternalImportRouter.global[impsRouter] = NeedVerifyDataObject[initCheckItem][impsRouter];
                                                    }
                                                }
                                                break;
                                        }
                                    }
                                    break;
                                case "[object Array]":
                                    if (!Instance.__MeTools.RouterMiddlewareCheck(Instance, NeedVerifyDataObject[initCheckItem])) {
                                        throw new Error("ExternalImportRouter属性要导入的路由数组异常！");
                                    } else {
                                        for (let imp in NeedVerifyDataObject[initCheckItem]) {
                                            let detectVal = arrRouterDetect(NeedVerifyDataObject[initCheckItem][imp]);
                                            if (detectVal[detectVal.length - 1]) {
                                                switch (String(detectVal[2]).toLowerCase()) {
                                                    case "http":
                                                        if (typeof tempTestObject.ExternalImportRouter.http === "object") {
                                                            tempTestObject.ExternalImportRouter.http[detectVal[0]] = detectVal[1];
                                                        } else {
                                                            tempTestObject.ExternalImportRouter.http = {};
                                                            tempTestObject.ExternalImportRouter.http[detectVal[0]] = detectVal[1];
                                                        }
                                                        break;
                                                    case "https":
                                                        if (typeof tempTestObject.ExternalImportRouter.https === "object") {
                                                            tempTestObject.ExternalImportRouter.https[detectVal[0]] = detectVal[1];
                                                        } else {
                                                            tempTestObject.ExternalImportRouter.https = {};
                                                            tempTestObject.ExternalImportRouter.https[detectVal[0]] = detectVal[1];
                                                        }
                                                        break;
                                                    default:
                                                        if (typeof tempTestObject.ExternalImportRouter.global === "object") {
                                                            tempTestObject.ExternalImportRouter.global[detectVal[0]] = detectVal[1];
                                                        } else {
                                                            tempTestObject.ExternalImportRouter.global = {};
                                                            tempTestObject.ExternalImportRouter.global[detectVal[0]] = detectVal[1];
                                                        }
                                                        break;
                                                }
                                            }
                                        }
                                    }
                                    break;
                                default:
                                    throw new Error("ExternalImportRouter属性仅支持特定格式的数组、对象！");
                            }
                            break;
                        case "enablehistoryrouter":
                            switch (Object.prototype.toString.call(NeedVerifyDataObject[initCheckItem])) {
                                case "[object Object]":
                                    tempTestObject.EnableHistoryRouter = {};
                                    if (Instance.__MeTools.BasicTools.emptyObjDetect(NeedVerifyDataObject[initCheckItem])) {
                                        throw new Error("EnableHistoryRouter属性包含的对象是空对象！");
                                    } else {
                                        for (let shr in NeedVerifyDataObject[initCheckItem]) {
                                            switch (shr.toLowerCase()) {
                                                case "http":
                                                    if (Object.prototype.toString.call(NeedVerifyDataObject[initCheckItem][shr]) !== "[object Boolean]") {
                                                        throw new Error("EnableHistoryRouter属性对象包含的http属性必须是布尔值！");
                                                    } else {
                                                        tempTestObject.EnableHistoryRouter.http = Instance.__MeTools.BasicTools.Light_Copy(NeedVerifyDataObject[initCheckItem][shr]);
                                                    }
                                                    break;
                                                case "https":
                                                    if (Object.prototype.toString.call(NeedVerifyDataObject[initCheckItem][shr]) !== "[object Boolean]") {
                                                        throw new Error("EnableHistoryRouter属性对象包含的https属性必须是布尔值！");
                                                    } else {
                                                        tempTestObject.EnableHistoryRouter.https = Instance.__MeTools.BasicTools.Light_Copy(NeedVerifyDataObject[initCheckItem][shr]);
                                                    }
                                                    break;
                                                default:
                                                    throw new Error("EnableHistoryRouter属性包含的对象出现未知的属性！");
                                            }
                                        }
                                    }
                                    break;
                                case "[object Boolean]":
                                    tempTestObject.EnableHistoryRouter = Instance.__MeTools.BasicTools.Light_Copy(NeedVerifyDataObject[initCheckItem]);
                                    break;
                                default:
                                    throw new Error("EnableHistoryRouter属性仅能为对象或布尔值！");
                            }
                            break;
                        case "defaultrootpath":
                            switch (Object.prototype.toString.call(NeedVerifyDataObject[initCheckItem])) {
                                case "[object Object]":
                                    if (Instance.__MeTools.BasicTools.emptyObjDetect(NeedVerifyDataObject[initCheckItem])) {
                                        throw new Error("DefaultRootPath属性包含的对象是空对象！");
                                    } else {
                                        tempTestObject.DefaultRootPath = {};
                                        for (let PathType in NeedVerifyDataObject[initCheckItem]) {
                                            switch (PathType.toLowerCase()) {
                                                case"http":
                                                    tempTestObject.DefaultRootPath.http = Instance.__MeTools.BasicTools.Light_Copy(NeedVerifyDataObject[initCheckItem][PathType]);
                                                    break;
                                                case"https":
                                                    tempTestObject.DefaultRootPath.https = Instance.__MeTools.BasicTools.Light_Copy(NeedVerifyDataObject[initCheckItem][PathType]);
                                                    break;
                                                default:
                                                    throw new Error("出现未知的属性！");
                                            }
                                        }
                                    }
                                    break;
                                case "[object String]":
                                    tempTestObject.DefaultRootPath = Instance.__MeTools.BasicTools.Light_Copy(NeedVerifyDataObject[initCheckItem]);
                                    break;
                                default:
                                    throw new Error("DefaultRootPath属性仅能为对象或字符串！");
                            }
                            break;
                        case "defaultpage":
                            switch (Object.prototype.toString.call(NeedVerifyDataObject[initCheckItem])) {
                                case "[object Object]":
                                    if (Instance.__MeTools.BasicTools.emptyObjDetect(NeedVerifyDataObject[initCheckItem])) {
                                        throw new Error("DefaultPage属性包含的对象是空对象！");
                                    } else {
                                        tempTestObject.DefaultPage = {};
                                        for (let PathType in NeedVerifyDataObject[initCheckItem]) {
                                            switch (PathType.toLowerCase()) {
                                                case"http":
                                                    if (Object.prototype.toString.call(NeedVerifyDataObject[initCheckItem][PathType]) !== "[object String]") {
                                                        throw new Error("http服务根目录的默认文件为非字符串内容！");
                                                    } else {
                                                        tempTestObject.DefaultPage.http = Instance.__MeTools.BasicTools.Light_Copy(NeedVerifyDataObject[initCheckItem][PathType]);
                                                    }
                                                    break;
                                                case"https":
                                                    if (Object.prototype.toString.call(NeedVerifyDataObject[initCheckItem][PathType]) !== "[object String]") {
                                                        throw new Error("https服务根目录的默认文件为非字符串内容！");
                                                    } else {
                                                        tempTestObject.DefaultPage.https = Instance.__MeTools.BasicTools.Light_Copy(NeedVerifyDataObject[initCheckItem][PathType]);
                                                    }
                                                    break;
                                                default:
                                                    throw new Error("出现未知的属性！");
                                            }
                                        }
                                    }
                                    break;
                                case "[object String]":
                                    tempTestObject.DefaultPage = Instance.__MeTools.BasicTools.Light_Copy(NeedVerifyDataObject[initCheckItem]);
                                    break
                                case "[object Undefined]":
                                    tempTestObject.DefaultPage = undefined;
                                    break;
                                case "[object Null]":
                                    tempTestObject.DefaultPage = null;
                                    break;
                                default:
                                    throw new Error("DefaultPage属性仅能为对象或字符串！");
                            }
                            break;
                        case "sslprivatekey":
                            tempTestObject.SSLPrivateKey = NeedVerifyDataObject[initCheckItem];
                            break;
                        case "sslcertificate":
                            tempTestObject.SSLCertificate = NeedVerifyDataObject[initCheckItem];
                            break;
                        case "serviceport":
                            switch (Object.prototype.toString.call(NeedVerifyDataObject[initCheckItem])) {
                                case "[object Object]":
                                    if (Instance.__MeTools.BasicTools.emptyObjDetect(NeedVerifyDataObject[initCheckItem])) {
                                        throw new Error("ServicePort属性包含的对象是空对象！");
                                    } else {
                                        tempTestObject.ServicePort = {};
                                        for (let PortType in NeedVerifyDataObject[initCheckItem]) {
                                            switch (PortType.toLowerCase()) {
                                                case"http":
                                                    if (Instance.__MeTools.BasicTools.PortRangeDetect(NeedVerifyDataObject[initCheckItem][PortType])) {
                                                        tempTestObject.ServicePort.http = Instance.__MeTools.BasicTools.Light_Copy(NeedVerifyDataObject[initCheckItem][PortType]);
                                                    } else {
                                                        throw new Error("端口号设置异常！");
                                                    }
                                                    break;
                                                case"https":
                                                    if (Instance.__MeTools.BasicTools.PortRangeDetect(NeedVerifyDataObject[initCheckItem][PortType])) {
                                                        tempTestObject.ServicePort.https = Instance.__MeTools.BasicTools.Light_Copy(NeedVerifyDataObject[initCheckItem][PortType]);
                                                    } else {
                                                        throw new Error("端口号设置异常！");
                                                    }
                                                    break;
                                                default:
                                                    throw new Error("出现未知的属性！");
                                            }
                                        }
                                    }
                                    break;
                                case "[object Number]":
                                    if (Instance.__MeTools.BasicTools.PortRangeDetect(NeedVerifyDataObject[initCheckItem])) {
                                        tempTestObject.ServicePort = Instance.__MeTools.BasicTools.Light_Copy(NeedVerifyDataObject[initCheckItem]);
                                    } else {
                                        throw new Error("端口号设置异常！");
                                    }
                                    break;
                                default:
                                    throw new Error("ServicePort属性必须为对象或为正整数！");
                            }
                            break;
                        case "servicehost":
                            switch (Object.prototype.toString.call(NeedVerifyDataObject[initCheckItem])) {
                                case "[object Object]":
                                    if (Instance.__MeTools.BasicTools.emptyObjDetect(NeedVerifyDataObject[initCheckItem])) {
                                        throw new Error("ServiceHost 属性的数据是空对象！");
                                    } else {
                                        tempTestObject.ServiceHost = {};
                                        for (let hostChk in NeedVerifyDataObject[initCheckItem]) {
                                            let detectValue = false;
                                            switch (hostChk.toLowerCase()) {
                                                case "http":
                                                    switch (Object.prototype.toString.call(NeedVerifyDataObject[initCheckItem][hostChk])) {
                                                        case "[object String]":
                                                            detectValue = Instance.__MeTools.IPAddressComps(Instance, NeedVerifyDataObject[initCheckItem][hostChk]);
                                                            if (detectValue) {
                                                                tempTestObject.ServiceHost.http = Instance.__MeTools.BasicTools.Light_Copy(NeedVerifyDataObject[initCheckItem][hostChk])
                                                            } else {
                                                                throw new Error("http属性指定的主机名称或IP地址无效！");
                                                            }
                                                            break;
                                                        case "[object Undefined]":
                                                            tempTestObject.ServiceHost.http = undefined;
                                                            break;
                                                        default:
                                                            throw new Error("ServiceHost属性下的http属性的数据不是字符串！");
                                                    }
                                                    break;
                                                case "https":
                                                    switch (Object.prototype.toString.call(NeedVerifyDataObject[initCheckItem][hostChk])) {
                                                        case "[object String]":
                                                            detectValue = Instance.__MeTools.IPAddressComps(Instance, NeedVerifyDataObject[initCheckItem][hostChk]);
                                                            if (detectValue) {
                                                                tempTestObject.ServiceHost.https = Instance.__MeTools.BasicTools.Light_Copy(NeedVerifyDataObject[initCheckItem][hostChk])
                                                            } else {
                                                                throw new Error("http属性指定的主机名称或IP地址无效！");
                                                            }
                                                            break;
                                                        case "[object Undefined]":
                                                            tempTestObject.ServiceHost.https = undefined;
                                                            break;
                                                        default:
                                                            throw new Error("ServiceHost属性下的https属性的数据不是字符串！");
                                                    }
                                                    break;
                                                default:
                                                    throw new Error("出现未知的属性！");
                                            }
                                        }
                                    }
                                    break;
                                case "[object String]":
                                    if (Instance.__MeTools.IPAddressComps(Instance, NeedVerifyDataObject[initCheckItem])) {
                                        tempTestObject.ServiceHost = Instance.__MeTools.BasicTools.Light_Copy(NeedVerifyDataObject[initCheckItem]);
                                    } else {
                                        throw new Error("ServiceHost属性指定的主机名称或IP地址无效！");
                                    }
                                    break;
                                case "[object Undefined]":
                                    tempTestObject.ServiceHost = undefined;
                                    break;
                                case "[object Null]":
                                    tempTestObject.ServiceHost = null;
                                    break;
                                default:
                                    throw new Error("ServiceHost属性仅能为对象或字符串！");
                            }
                            break;
                        case "specialsupport":
                            switch (Object.prototype.toString.call(NeedVerifyDataObject[initCheckItem])) {
                                case "[object Object]":
                                    if (Instance.__MeTools.BasicTools.emptyObjDetect(NeedVerifyDataObject[initCheckItem]) === true) {
                                        throw new Error("SpecialSupport 属性不能为空对象！");
                                    }
                                    tempTestObject.SpecialSupport = {}
                                    for (let chkObj in NeedVerifyDataObject[initCheckItem]) {
                                        switch (chkObj.toLowerCase()) {
                                            case "http":
                                                if (Object.prototype.toString.call(NeedVerifyDataObject[initCheckItem][chkObj]) !== "[object Array]"
                                                    ||
                                                    Instance.__MeTools.BasicTools.emptyArrDetect(NeedVerifyDataObject[initCheckItem][chkObj]) === true) {
                                                    throw new Error("导入至SpecialSupport属性的http服务分支的支持件数据不是数组，也不能为空数组！");
                                                }
                                                tempTestObject.SpecialSupport.http = [];
                                                for (let chkImpSupportHttp in NeedVerifyDataObject[initCheckItem][chkObj]) {
                                                    if (Object.prototype.toString.call(NeedVerifyDataObject[initCheckItem][chkObj][chkImpSupportHttp]) !== "[object Function]"
                                                        &&
                                                        Object.prototype.toString.call(NeedVerifyDataObject[initCheckItem][chkObj][chkImpSupportHttp]) !== "[object AsyncFunction]"
                                                        &&
                                                        Object.prototype.toString.call(NeedVerifyDataObject[initCheckItem][chkObj][chkImpSupportHttp]) !== "[object String]"
                                                    ) {
                                                        throw new Error("导入至SpecialSupport属性的http服务分支的支持件不是函数也不是异步函数也不是字符串！");
                                                    }
                                                    tempTestObject.SpecialSupport.http.push(NeedVerifyDataObject[initCheckItem][chkObj][chkImpSupportHttp]);
                                                }
                                                break;
                                            case "https":
                                                if (Object.prototype.toString.call(NeedVerifyDataObject[initCheckItem][chkObj]) !== "[object Array]"
                                                    ||
                                                    Instance.__MeTools.BasicTools.emptyArrDetect(NeedVerifyDataObject[initCheckItem][chkObj]) === true) {
                                                    throw new Error("导入至SpecialSupport属性的https服务分支的支持件数据不是数组，也不能为空数组！");
                                                }
                                                tempTestObject.SpecialSupport.https = [];
                                                for (let chkImpSupportHttps in NeedVerifyDataObject[initCheckItem][chkObj]) {
                                                    if (Object.prototype.toString.call(NeedVerifyDataObject[initCheckItem][chkObj][chkImpSupportHttps]) !== "[object Function]"
                                                        &&
                                                        Object.prototype.toString.call(NeedVerifyDataObject[initCheckItem][chkObj][chkImpSupportHttps]) !== "[object AsyncFunction]"
                                                        &&
                                                        Object.prototype.toString.call(NeedVerifyDataObject[initCheckItem][chkObj][chkImpSupportHttps]) !== "[object String]"
                                                    ) {
                                                        throw new Error("导入至SpecialSupport属性的https服务分支的支持件不是函数也不是异步函数也不是字符串！");
                                                    }
                                                    tempTestObject.SpecialSupport.https.push(NeedVerifyDataObject[initCheckItem][chkObj][chkImpSupportHttps]);
                                                }
                                                break;
                                            case "global":
                                                if (Object.prototype.toString.call(NeedVerifyDataObject[initCheckItem][chkObj]) !== "[object Array]"
                                                    ||
                                                    Instance.__MeTools.BasicTools.emptyArrDetect(NeedVerifyDataObject[initCheckItem][chkObj]) === true) {
                                                    throw new Error("导入至SpecialSupport属性的global服务分支的支持件数据不是数组，也不能为空数组！");
                                                }
                                                tempTestObject.SpecialSupport.global = [];
                                                for (let chkImpSupportGlobal in NeedVerifyDataObject[initCheckItem][chkObj]) {
                                                    if (Object.prototype.toString.call(NeedVerifyDataObject[initCheckItem][chkObj][chkImpSupportGlobal]) !== "[object Function]"
                                                        &&
                                                        Object.prototype.toString.call(NeedVerifyDataObject[initCheckItem][chkObj][chkImpSupportGlobal]) !== "[object AsyncFunction]"
                                                        &&
                                                        Object.prototype.toString.call(NeedVerifyDataObject[initCheckItem][chkObj][chkImpSupportGlobal]) !== "[object String]"
                                                    ) {
                                                        throw new Error("导入至SpecialSupport属性的global服务分支的支持件不是函数也不是异步函数也不是字符串！");
                                                    }
                                                    tempTestObject.SpecialSupport.global.push(NeedVerifyDataObject[initCheckItem][chkObj][chkImpSupportGlobal]);
                                                }
                                                break;
                                            default:
                                                throw new Error("SpecialSupport 属性内出现未知的属性分支！");
                                        }
                                    }
                                    break;
                                case "[object Array]":
                                    if (Instance.__MeTools.BasicTools.emptyArrDetect(NeedVerifyDataObject[initCheckItem]) === true) {
                                        throw new Error("SpecialSupport 属性不能为空数组！");
                                    }
                                    // tempTestObject.SpecialSupport = {global: []};
                                    tempTestObject.SpecialSupport = [];
                                    for (let chkArr in NeedVerifyDataObject[initCheckItem]) {
                                        switch (Object.prototype.toString.call(NeedVerifyDataObject[initCheckItem][chkArr])) {
                                            case "[object Function]":
                                                tempTestObject.SpecialSupport.push(NeedVerifyDataObject[initCheckItem][chkArr]);
                                                // tempTestObject.SpecialSupport.global.push(NeedVerifyDataObject[initCheckItem][chkArr]);
                                                break;
                                            case "[object AsyncFunction]":
                                                tempTestObject.SpecialSupport.push(NeedVerifyDataObject[initCheckItem][chkArr]);
                                                // tempTestObject.SpecialSupport.global.push(NeedVerifyDataObject[initCheckItem][chkArr]);
                                                break;
                                            case "[object String]":
                                                tempTestObject.SpecialSupport.push(NeedVerifyDataObject[initCheckItem][chkArr]);
                                                // tempTestObject.SpecialSupport.global.push(NeedVerifyDataObject[initCheckItem][chkArr]);
                                                break;
                                            default:
                                                throw new Error("导入至SpecialSupport属性的支持件不是函数也不是异步函数也不是字符串！");
                                        }
                                    }
                                    break;
                                case "[object Undefined]":
                                    tempTestObject.SpecialSupport = undefined;
                                    break;
                                case "[object Null]":
                                    tempTestObject.SpecialSupport = null;
                                    break;
                                default:
                                    throw new Error("SpecialSupport 属性必须是有效对象或包含支持件的数组！");
                            }
                            break;
                        case "norequiredstaticresources":
                            switch (Object.prototype.toString.call(NeedVerifyDataObject[initCheckItem])) {
                                case "[object Object]":
                                    tempTestObject.NoRequiredStaticResources = {};
                                    for (let chkAttr in NeedVerifyDataObject[initCheckItem]) {
                                        switch (chkAttr.toLowerCase()) {
                                            case "http":
                                                if (Object.prototype.toString.call(NeedVerifyDataObject[initCheckItem][chkAttr]) !== "[object Boolean]") {
                                                    throw new Error("不需要指定静态资源（NoRequiredStaticResources）属性内的http属性不是布尔值！");
                                                }
                                                tempTestObject.NoRequiredStaticResources.http = Instance.__MeTools.BasicTools.Light_Copy(NeedVerifyDataObject[initCheckItem][chkAttr]);
                                                break;
                                            case "https":
                                                if (Object.prototype.toString.call(NeedVerifyDataObject[initCheckItem][chkAttr]) !== "[object Boolean]") {
                                                    throw new Error("不需要指定静态资源（NoRequiredStaticResources）属性内的https属性不是布尔值！");
                                                }
                                                tempTestObject.NoRequiredStaticResources.https = Instance.__MeTools.BasicTools.Light_Copy(NeedVerifyDataObject[initCheckItem][chkAttr]);
                                                break;
                                            default:
                                                throw new Error("不需要指定静态资源（NoRequiredStaticResources）属性内出现未知的属性！");
                                        }
                                    }
                                    break;
                                case "[object Boolean]":
                                    tempTestObject.NoRequiredStaticResources = Instance.__MeTools.BasicTools.Light_Copy(NeedVerifyDataObject[initCheckItem]);
                                    break;
                                default:
                                    throw new Error("不需要指定静态资源（NoRequiredStaticResources）属性的内容值不是有效对象也不是布尔值！");
                            }
                            break;
                        case "globaleventjoinpoint":
                            if (typeof NeedVerifyDataObject[initCheckItem] === "function") {
                                tempTestObject.GlobalEventJoinPoint = NeedVerifyDataObject[initCheckItem];
                            } else {
                                tempTestObject.GlobalEventJoinPoint = undefined
                            }
                            break;
                        default:
                            throw new Error("出现未知的配置属性！");
                    }
                }
                let {SSLCertificate, SSLPrivateKey, ServicePort, DefaultRootPath, DefaultPage, NoRequiredStaticResources} = tempTestObject;
                let path1, path2, page1, page2, bt1, bt2, http_StaticResource = false, https_StaticResource = false;
                if (typeof DefaultRootPath === "object") {
                    path1 = DefaultRootPath.http;
                    path2 = DefaultRootPath.https;
                } else {
                    path1 = DefaultRootPath;
                    path2 = DefaultRootPath;
                }
                if (typeof DefaultPage === "object") {
                    page1 = DefaultPage.http;
                    page2 = DefaultPage.https;
                } else {
                    page1 = DefaultPage;
                    page2 = DefaultPage;
                }

                function Static_ResourceDetect(Instance, path, target) {
                    let StaticFinalDetectValue = [];
                    if (Instance.__MeTools.BasicTools.FileStream.existsSync(path)) {
                        StaticFinalDetectValue.push(true);
                    } else {
                        StaticFinalDetectValue.push(false);
                    }
                    if (Instance.__MeTools.BasicTools.FileStream.existsSync(Instance.__MeTools.BasicTools.PathStream.join(path, target))) {
                        StaticFinalDetectValue.push(true);
                    } else {
                        StaticFinalDetectValue.push(false);
                    }
                    return StaticFinalDetectValue;
                }

                function Static_detectProcess(option, v1, v2) {
                    let confirmCount = 0;
                    let http, https;
                    switch (typeof option) {
                        case "object":
                            http = option.http;
                            https = option.https;
                            if (!http) {
                                if (typeof v1 === "object" && v1[0] && v1[1]) {
                                    confirmCount++;
                                }
                            } else {
                                confirmCount++;
                            }
                            if (!https) {
                                if (typeof v2 === "object" && v2[0] && v2[1]) {
                                    confirmCount++;
                                }
                            } else {
                                confirmCount++;
                            }
                            break;
                        case "boolean":
                            if (!option) {
                                if (typeof v1 === "object" && v1[0] && v1[1]) {
                                    confirmCount++;
                                }
                                if (typeof v2 === "object" && v2[0] && v2[1]) {
                                    confirmCount++;
                                }
                            } else {
                                confirmCount++;
                            }
                            break;
                    }
                    if (confirmCount > 0) {
                        return true;
                    } else {
                        return false;
                    }
                }

                function SSL_authDetect(Instance, cert, keys) {
                    if (
                        Instance.__MeTools.BasicTools.FileStream.existsSync(cert)
                        &&
                        Instance.__MeTools.BasicTools.FileStream.existsSync(keys)
                    ) {
                        return true;
                    } else {
                        return false;
                    }
                }

                if (typeof NoRequiredStaticResources === "object") {
                    http_StaticResource = NoRequiredStaticResources.http;
                    https_StaticResource = NoRequiredStaticResources.https;
                } else {
                    http_StaticResource = NoRequiredStaticResources;
                    https_StaticResource = NoRequiredStaticResources;
                }
                switch (Instance.__MeTools.ModeLauncherSelect(tempTestObject)) {
                    case"both":
                        if (!http_StaticResource) {
                            bt1 = Static_ResourceDetect(Instance, path1, page1);
                        }
                        if (!https_StaticResource) {
                            bt2 = Static_ResourceDetect(Instance, path2, page2);
                        }
                        if (!Static_detectProcess(NoRequiredStaticResources, bt1, bt2)) {
                            throw new Error("静态资源异常！");
                        }
                        if (typeof ServicePort !== "object") {
                            throw new Error("服务端口不能共用一个！");
                        } else {
                            let {http, https} = ServicePort;
                            if (http === undefined && https === undefined) {
                                throw new Error("http、https服务端口未指定！");
                            } else if (http === https) {
                                throw new Error("http、https服务端口不能相同！");
                            }
                        }
                        if (!SSL_authDetect(Instance, SSLCertificate, SSLPrivateKey)) {
                            throw new Error("SSL证书未指定！");
                        }
                        break;
                    case"http":
                        if (!http_StaticResource) {
                            bt1 = Static_ResourceDetect(Instance, path1, page1);
                            if (!Static_detectProcess(NoRequiredStaticResources, bt1, bt2)) {
                                throw new Error("静态资源异常！");
                            }
                        }
                        switch (typeof ServicePort) {
                            case "object":
                                let {http} = ServicePort;
                                if (http === undefined) {
                                    throw new Error("http服务端口未指定！");
                                }
                                break;
                        }
                        break;
                    case"https":
                        if (!https_StaticResource) {
                            bt2 = Static_ResourceDetect(Instance, path2, page2);
                            if (!Static_detectProcess(NoRequiredStaticResources, bt1, bt2)) {
                                throw new Error("静态资源异常！");
                            }
                        }
                        switch (typeof ServicePort) {
                            case "object":
                                let {https} = ServicePort;
                                if (https === undefined) {
                                    throw new Error("https服务端口未指定！");
                                }
                                break;
                        }
                        if (!SSL_authDetect(Instance, SSLCertificate, SSLPrivateKey)) {
                            throw new Error("SSL证书未指定！");
                        }
                        break;
                    default:
                        throw new Error("未指定使用一项服务！");
                }
            }
            Instance.__InstanceCollect_Root.confirmPassData = undefined;
            Instance.__InstanceCollect_Root.confirmPassData = Instance.__MeTools.BasicTools.Light_Copy(tempTestObject);
            VerifyBooleanValue = true;
        } catch (e) {
            Instance.__InstanceCollect_Root.consoleLogStream.addonLog(Instance, `${e.message}\r\n${e.stack}`, 'Fail');
            VerifyBooleanValue = false
        }
        return VerifyBooleanValue;
    },
    ConfigureDataReady(InstanceHandle) {
        let FinalCollectionObject = {};
        if (InstanceHandle.__MeTools.InstanceIntegrityVerify(InstanceHandle)) {
            for (let CollectAttrName in InstanceHandle) {
                switch (CollectAttrName) {
                    case "EnableHttpsMode":
                        FinalCollectionObject.EnableHttpsMode = InstanceHandle.__MeTools.BasicTools.Light_Copy(InstanceHandle[CollectAttrName]);
                        break;
                    case "EnableHttpMode":
                        FinalCollectionObject.EnableHttpMode = InstanceHandle.__MeTools.BasicTools.Light_Copy(InstanceHandle[CollectAttrName]);
                        break;
                    case "ExternalImportRouter":
                        switch (Object.prototype.toString.call(InstanceHandle[CollectAttrName])) {
                            case "[object Object]":
                                FinalCollectionObject.ExternalImportRouter = InstanceHandle.__MeTools.BasicTools.Light_Copy(InstanceHandle[CollectAttrName]);
                                break;
                            case "[object Array]":
                                FinalCollectionObject.ExternalImportRouter = InstanceHandle.__MeTools.BasicTools.Light_Copy(InstanceHandle[CollectAttrName]);
                                break;
                        }
                        break;
                    case "EnableHistoryRouter":
                        FinalCollectionObject.EnableHistoryRouter = InstanceHandle.__MeTools.BasicTools.Light_Copy(InstanceHandle[CollectAttrName]);
                        break;
                    case "DefaultPage":
                        FinalCollectionObject.DefaultPage = InstanceHandle.__MeTools.BasicTools.Light_Copy(InstanceHandle[CollectAttrName]);
                        break;
                    case "DefaultRootPath":
                        FinalCollectionObject.DefaultRootPath = InstanceHandle.__MeTools.BasicTools.Light_Copy(InstanceHandle[CollectAttrName]);
                        break;
                    case "ServicePort":
                        FinalCollectionObject.ServicePort = InstanceHandle.__MeTools.BasicTools.Light_Copy(InstanceHandle[CollectAttrName]);
                        break;
                    case "ServiceHost":
                        FinalCollectionObject.ServiceHost = InstanceHandle.__MeTools.BasicTools.Light_Copy(InstanceHandle[CollectAttrName]);
                        break;
                    case "SSLPrivateKey":
                        if (InstanceHandle.__MeTools.ModeLauncherSelect(InstanceHandle) === "https" || InstanceHandle.__MeTools.ModeLauncherSelect(InstanceHandle) === "both") {
                            FinalCollectionObject.SSLPrivateKey = InstanceHandle.__MeTools.BasicTools.Light_Copy(InstanceHandle[CollectAttrName]);
                        }
                        break;
                    case "SSLCertificate":
                        if (InstanceHandle.__MeTools.ModeLauncherSelect(InstanceHandle) === "https" || InstanceHandle.__MeTools.ModeLauncherSelect(InstanceHandle) === "both") {
                            FinalCollectionObject.SSLCertificate = InstanceHandle.__MeTools.BasicTools.Light_Copy(InstanceHandle[CollectAttrName]);
                        }
                        break;
                    case "SpecialSupport":
                        FinalCollectionObject.SpecialSupport = InstanceHandle.__MeTools.BasicTools.Light_Copy(InstanceHandle[CollectAttrName]);
                        break;
                    case "NoRequiredStaticResources":
                        FinalCollectionObject.NoRequiredStaticResources = InstanceHandle.__MeTools.BasicTools.Light_Copy(InstanceHandle[CollectAttrName]);
                        break;
                    case "GlobalEventJoinPoint":
                        FinalCollectionObject.GlobalEventJoinPoint = InstanceHandle.__MeTools.BasicTools.Light_Copy(InstanceHandle[CollectAttrName]);
                        break;
                }
            }
            if (InstanceHandle.__MeTools.ConfigureDataVerify(InstanceHandle, FinalCollectionObject)) {
                return FinalCollectionObject;
            } else {
                return null;
            }
        } else {
            InstanceHandle.__InstanceCollect_Root.consoleLogStream.addonLog(InstanceHandle, "指向需要收集配置数据的实例对象不是本模块的实例对象！", "fail");
        }
    }
};